package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.goods.Good;
import com.blog.seckill.goods.ProductSku;
import com.blog.seckill.goods.ProductSpu;
import com.blog.service.ProductCategoryBaseService;
import com.blog.service.ProductSkuBaseService;
import com.blog.service.ProductSpuBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ProductSpuBaseController
 * @Destription ProductSpu基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/productSpu")
public class ProductSpuBaseController {
    @Autowired
    ProductSpuBaseService productSpuBaseService;
    @Autowired
    ProductSkuBaseService productSkuBaseService;
    @Autowired
    ProductCategoryBaseService productCategoryBaseService;
    @GetMapping("/selectAllGoods")
    public CommonRespDto selectAllGoods(){
        return CommonRespDto.success(productSpuBaseService.selectAllGoods());
    }
    @GetMapping("/base/selectProductSpuById/{rid}")
    public CommonRespDto selectProductSpuById(@PathVariable Integer rid){
        return CommonRespDto.success(productSpuBaseService.selectProductSpuById(rid.longValue()));
    }

    @PostMapping("/base/insertProductSpu")
    public RespBean insertProductSpu(@RequestBody ProductSpu productSpu){
        if(productSpuBaseService.insertProductSpu(productSpu) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteProductSpu/{rid}")
    public RespBean deleteProductSpuById(@PathVariable Integer rid){
        if(productSpuBaseService.deleteProductSpuById(rid.longValue()) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateProductSpu")
    public RespBean updateProductSpu(@RequestBody ProductSpu productSpu){

        if(productSpuBaseService.updateProductSpu(productSpu) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
